package common

import (
	"context"
	"github.com/gogf/gf/v2/errors/gcode"
	"github.com/gogf/gf/v2/errors/gerror"
	"github.com/gogf/gf/v2/util/gutil"
	"zuhao-seucre/api/common/v1"
	"zuhao-seucre/utility/cryptox"
)

func (c *ControllerV1) PublicKey(ctx context.Context, req *v1.PublicKeyReq) (res *v1.PublicKeyRes, err error) {
	publicKeyStr, err := cryptox.GetRsaPublicKey(ctx)
	if gutil.IsEmpty(publicKeyStr) {
		err = gerror.NewCode(gcode.CodeNotFound)
		return
	}
	res = new(v1.PublicKeyRes)
	*res = v1.PublicKeyRes(publicKeyStr)
	return
}
